﻿@model ProductVariantAttributeCombinationModel

@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)@*otherwise we get a model state error*@

<div class="well">
	@if (ViewBag.IsEdit)
    {
		@Html.Raw(Html.TableFormattedVariantAttributes(Model.AttributesXml))
    }
    else
    {
		<div id="ProductVariantAttributeContainer">
			@{ Html.RenderPartial("_ProductAttributes", Model); }
		</div>
	}
</div>

@if (!ViewBag.IsEdit)
{
	<div id="CombinationExistenceNote">
		@if (Model.Warnings.Count > 0)
		{
			<div class="alert alert-warning">
				@foreach (var warning in Model.Warnings)
				{
					<p><i class="fa fa-exclamation-triangle"></i>&nbsp;@warning</p>
				}
			</div>
		}
	</div>
}

<div>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.IsActive)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.IsActive)
                @Html.ValidationMessageFor(model => model.IsActive)
            </td>
        </tr>
        <tr class="adminSeparator">
            <td colspan="2"><hr /></td>
        </tr>
		<tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.AssignedPictureIds)
            </td>
            <td class="adminData">
				<ul class="choice-box-group choice-box-group-xl mb-1" id="assigned-pictures">
					@foreach (var x in Model.AssignablePictures)
					{
						<li class="choice-box">
							<label class="choice-box-label">
								<input type="checkbox" class="choice-box-control-native" name="AssignedPictureIds" value="@x.Id" @Html.Attr("checked", "checked", x.IsAssigned)>
								<span class="choice-box-content">
									<span class="choice-box-element" style="background-image:url('@x.PictureUrl')"></span>
								</span>
							</label>
						</li>
					}
				</ul>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.Sku)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Sku)
                @Html.ValidationMessageFor(model => model.Sku)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.ManufacturerPartNumber)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.ManufacturerPartNumber)
                @Html.ValidationMessageFor(model => model.ManufacturerPartNumber)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.Gtin)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Gtin)
                @Html.ValidationMessageFor(model => model.Gtin)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.Price)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Price, new { postfix = Model.PrimaryStoreCurrencyCode })
                @Html.ValidationMessageFor(model => model.Price)
            </td>
        </tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.DeliveryTimeId)
			</td>
			<td class="adminData">
				@Html.DropDownListFor(model => model.DeliveryTimeId, Model.AvailableDeliveryTimes, T("Common.Unspecified"))
				@Html.ValidationMessageFor(model => model.DeliveryTimeId)
			</td>
		</tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.BasePriceBaseAmount)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.BasePriceBaseAmount)
                @Html.ValidationMessageFor(model => model.BasePriceBaseAmount)
            </td>
        </tr>
		<tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.BasePriceAmount)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.BasePriceAmount)
                @Html.ValidationMessageFor(model => model.BasePriceAmount)
            </td>
        </tr>
        <tr class="adminSeparator">
            <td colspan="2"><hr /></td>
        </tr>
        <tr id="pnlLength">
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.Length)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Length, new { postfix = Model.BaseDimensionIn })
                @Html.ValidationMessageFor(model => model.Length)
            </td>
        </tr>
        <tr id="pnlWidth">
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.Width)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Width, new { postfix = Model.BaseDimensionIn })
                @Html.ValidationMessageFor(model => model.Width)
            </td>
        </tr>
        <tr id="pnlHeight">
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.Height)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Height, new { postfix = Model.BaseDimensionIn })
                @Html.ValidationMessageFor(model => model.Height)
            </td>
        </tr>
        <tr class="adminSeparator">
            <td colspan="2"><hr /></td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.StockQuantity)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.StockQuantity)
                @Html.ValidationMessageFor(model => model.StockQuantity)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.AllowOutOfStockOrders)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.AllowOutOfStockOrders)
                @Html.ValidationMessageFor(model => model.AllowOutOfStockOrders)
            </td>
        </tr>
    </table>
</div>

<script type="text/javascript">
    $(function () {
		var container = $('#ProductVariantAttributeContainer'),
			note = $('#CombinationExistenceNote');

		container.find('select').selectWrapper();

		container.change(function() {
			note.empty();
			container.closest('form').doAjax({
				smallIcon: note,
				url: '@Url.Action("CombinationExistenceNote", "Product", new { productId = Model.ProductId })',
				callbackSuccess: function (resp) {
					var cls = (resp.HasWarning ? 'warning' : 'info'),
						ico = (resp.HasWarning ? 'warning-sign' : 'ok-sign');

					note.html('<div class="alert alert-' + cls + '" style="margin:0;"><i class="fa fa-' + ico + '"></i>&nbsp;' + resp.Message + '</div>');
				}
			});
		});
	});
</script>

